<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/2/19
 * Time: 11:28
 */

namespace app\admin\model;


use think\Db;

class News extends BaseModel
{
    /**
     * 返回带有栏目名称的分页数据
     * @param $page
     * @param $pageSize
     * @param $where
     * @param $order
     * @param $field
     * @return array
     * @throws \think\exception\DbException
     */
    public static function getPageListWithNewsCate($page,$pageSize,$where,$order,$field)
    {
        $list = Db::name("news_cate")->alias("a")
            ->join("news b","a.id = b.cate_id")
            ->where($where)
            ->order($order)
            ->field($field)
            ->paginate(array('list_rows' => $pageSize, 'page' => $page))
            ->toArray();
        return $list;
    }

    /**
     * 获取首页的6条新闻
     * @param $where
     * @param $field
     * @param $order
     * @param $offset
     * @param $limit
     * @return array|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function getLimitList($where,$field,$order,$offset,$limit)
    {
        $list = Db::name("news")
            ->where($where)
            ->field($field)
            ->order($order)
            ->limit($offset,$limit)
            ->select();
        return $list;
    }
}